﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElevateAVIMotion.Model
{   
    public class SQLite
    {
        private SQLiteConnection mConnection;
        public bool Connect(string connectStr)
        {
            try
            {
                mConnection = new SQLiteConnection(connectStr);
                mConnection.Open();
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
        public void Disconnect()
        {
            if (mConnection != null)
            {
                mConnection.Close();
                mConnection.Dispose();
                mConnection = null;
            }
        }
        public DataSet ExecuteQuery(string strSQL)
        {
            DataSet da = new DataSet();
            SQLiteDataAdapter sda = new SQLiteDataAdapter(strSQL, mConnection);
            int m = sda.Fill(da, "table0");
            sda.Dispose();
            return da;
        }
        public int ExecuteNonQuery(string strSQL)
        {
            SQLiteCommand cmd = new SQLiteCommand(strSQL, mConnection);
            return cmd.ExecuteNonQuery();
        }
    }
}
